package com.aistar.service.Impl;

import com.aistar.mapper.HonorMapper;
import com.aistar.pojo.Honor;
import com.aistar.pojo.HonorExample;
import com.aistar.service.HonorService;
import com.aistar.util.ServerResponse;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class HonorServiceImpl implements HonorService {
    @Autowired
    private HonorMapper honorMapper;
    @Override
    public ServerResponse add(Honor honor) {

        int rows = honorMapper.insert(honor);

        if(rows >0)
            return ServerResponse.addSuccess();
        return ServerResponse.addFailed();


    }

    @Override
    public ServerResponse modify(Honor honor) {

        int rows = honorMapper.updateByPrimaryKeySelective(honor);

        if (rows>0)
            return ServerResponse.updateSuccess();
        return ServerResponse.updateFailed();
    }

    @Override
    public ServerResponse modifyStatus(Honor honor) {
        return null;
    }

    @Override
    public ServerResponse getById(Integer id) {

        Honor honor = honorMapper.selectByPrimaryKey(id);

        if(honor !=null)
            return ServerResponse.getDateSuccess(honor);
        return ServerResponse.getDataFailed("没有该荣誉");
    }

    @Override
    public ServerResponse getAll() {
        return null;
    }

    @Override
    public ServerResponse getAllByResumeId(Integer resumeId) {

        HonorExample example = new HonorExample();

        example.createCriteria().andResumeIdEqualTo(resumeId).andStatusEqualTo(0);

        List<Honor> honorList =  honorMapper.selectByExample(example);
        if(honorList!=null && honorList.size() >0)
            return ServerResponse.getDateSuccess(honorList);
        return ServerResponse.getDataFailed("暂无证书");

    }

    @Override
    public ServerResponse getLatestByResumeId(Integer resumeId) {

        HonorExample example =  new HonorExample();
        example.createCriteria().andResumeIdEqualTo(resumeId).andStatusEqualTo(0);
        example.setOrderByClause("honor_id desc");
        Honor honor = honorMapper.selectByExample(example).get(0);
        return ServerResponse.getDateSuccess(honor);
    }
}
